package universe;

public class BlockHandler {
	private int x;
	private int y;
	private Block b;
	private Board board;
	
	
	public BlockHandler(Block pBlock, Board pBoard){
		this.setBoard(pBoard);
		this.setB(pBlock);
		
		this.setX((int)((this.getBoard().getWidth()/2)-2));
		this.setY(1);
	}

	public boolean goDown(){
		boolean bReturn = (board.pushAllowed(b, x, y+1));
		
		if(bReturn)
			this.setY(this.getY()+1);	
		
		return bReturn;
		
		}
	
	public boolean goLeft()
	{
		boolean bReturn = (board.pushAllowed(b, x+1, y));
		
		if(bReturn)
			this.setX(this.getX()+1);	
		
		return bReturn;
		
			
	}
	
	public boolean goRight(){
		
		boolean bReturn = (board.pushAllowed(b, x-1, y));
		
		if(bReturn)
			this.setX(this.getX()-1);	
		
		return bReturn;
		
	}
	
	public void rotate(){
		this.getB().rotate();
	}
	
	
	//Getters and Setters
	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public Block getB() {
		return b;
	}

	public void setB(Block b) {
		this.b = b;
	}

	public Board getBoard() {
		return board;
	}

	public void setBoard(Board board) {
		this.board = board;
	}
}
